package com.hl.sfzy.controller;



import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Kechengshoucang;
import com.hl.sfzy.service.KechengshoucangService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/kechengshoucang")
public class KechengshoucangController {

    @Autowired
    private KechengshoucangService kechengshoucangService;

    @GetMapping("/findpage")
    public R findpage(	@RequestParam(required = false ,defaultValue = "1")int pageNum,                                 @RequestParam(required = false,defaultValue = "5") int pageSize,Kechengshoucang kechengshoucang){
        PageInfo<Kechengshoucang> findpage = kechengshoucangService.findpage(pageNum, pageSize, kechengshoucang);
        return R.ok(findpage);
    }

    @GetMapping("/{id}")
    public R selectByPrimaryKey(@PathVariable Long id) {
        Kechengshoucang kechengshoucang = kechengshoucangService.selectByPrimaryKey(id);
        if (kechengshoucang != null) {
            return R.ok(kechengshoucang);
        } else {
            return R.error("查询失败");
        }

    }
    @DeleteMapping("/{id}")
    public R deleteByPrimaryKey(@PathVariable Long id) {
        int result = kechengshoucangService.deleteByPrimaryKey(id);
        if (result > 0) {
            return R.ok("删除成功");
        } else {
            return R.error("删除失败");
        }
    }
    @PostMapping("/insert")
    public R insert(@RequestBody Kechengshoucang record) {
        int result = kechengshoucangService.insert(record);
        if (result > 0) {
            return R.ok("插入成功");
        } else {
            return R.fail("插入失败");
        }
    }

    @PostMapping("/selective")
    public R insertSelective(@RequestBody Kechengshoucang record) {
        int result = kechengshoucangService.insertSelective(record);
        if (result > 0) {
            return R.ok("插入成功");
        } else {
            return R.fail("插入失败");
        }
    }

    @PutMapping("/selective")
    public R updateByPrimaryKeySelective(@RequestBody Kechengshoucang record) {
        int result = kechengshoucangService.updateByPrimaryKeySelective(record);
        if (result > 0) {
            return R.ok("更新成功");
        } else {
            return R.fail("更新失败");
        }
    }

    @PutMapping("upda")
    public R updateByPrimaryKey(@RequestBody Kechengshoucang record) {
        int result = kechengshoucangService.updateByPrimaryKey(record);
        if (result > 0) {
            return R.ok("更新成功");
        }else {
            return R.fail("更新失败");
        }
    }




}
